<template>
  <div class="container">
    <van-nav-bar title="发现" />

    <div class="box">
      <div class="item" v-for="(item,key) in list" :key="key">
        <div class="top">
          <div class="avatar">
            <div class="image">
              <img :src="item.business.avatar_text" />
            </div>
            <div class="name">{{ item.business.nickname }}</div>
          </div>
          <!-- <div class="follow">
            <van-button type="primary" icon="plus" size="small" color="#7232dd">关注</van-button>
          </div> -->
        </div>
        
        <div class="title">{{ item.remark }}</div>

        <div class="thumbs">
          <van-uploader v-model="fileList[`${item.id}`]" multiple :max-count="9" readonly :deletable="false" preview-size="105" :show-upload="false"/>
        </div>

        <div class="product">
          <div class="left">
            <van-image
              width="70"
              height="50"
              :src="item.product.thumbs_text"
              @click="ProductInfo(item.product.id)"
            />
          </div>
          <div class="right">
            <div class="name">{{ item.product.name }}</div>
            <div class="price">￥{{item.product.price}}</div>
          </div>
        </div>

        <div class="action">
          <div class="left">{{ item.createtime_text }}</div>
          <div class="right" @click="shareStatus(item.id)">
            <div class="item" v-if="item.status==1 && busid">
              <van-icon name="like" />
              <span>{{ item.likes_text}}</span>
            </div>
            <div class="item" v-if="item.status==0">
              <van-icon name="like-o" />
              <span>{{ item.likes_text}}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>

  <Tabbar />
</template>

<script setup>
  const {proxy} = getCurrentInstance()
  //添加评论
  let ShowBottom = ref(false)
  //接受busid
  let busid = proxy.$business.value.id;
  let list = ref([])
  let fileList = ref([])
  onMounted(()=>{
    shareInfo()
  })
  const shareInfo = async ()=>{
      //发送请求
      var result = await proxy.$POST({
        url:'/index/share',
      })
      if(result.code == 0){
        proxy.$fail({
          message:result.msg,
          onClose:()=>proxy.$router.go(-1)
        })
      }
      result.data.map((item)=>{
        var pic = [];
        item.thumbs_text.map((val)=>pic.push({url:val}))//必须赋予url属性的值
        fileList.value[`${item.id}`] = pic
      })
      console.log(result.data);
      
      list.value = result.data;

  }
  //商品信息页面
  const ProductInfo = (proid)=>{
    proxy.$router.push({path:'/product/info',query:{proid:proid}})
  }
  const shareStatus = async (val)=>{
      if(!busid){
          proxy.$fail({
            message:'请先登录!',
            onClose:()=>proxy.$router.go(-1)
          })
      }
      var result = await proxy.$POST({
        url:'/index/status',
        params:{busid:busid,id:val},
      })
      if(result.code == 0){
        proxy.$fail(result.msg);
        return false
      }
      proxy.$success({
        message:result.msg,
        duration:200,
        onClose:()=>proxy.$router.go(0)
      })
  }
</script>

<style scoped>
  @import url('/assets/css/share.css');
</style>